#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os

def check_dir(dirpath):
    ret = os.walk(dirpath)
    for root, dirs, files in ret:
        pdir = os.path.split(root)[-1]
        if pdir == 'trunk' and 'CMakeLists.txt' in files and 'test' in dirs:
            for item in files:
                if len(item)>=5 and item[0:4] == 'ver_':
                    #print root, item
                    with open(root+os.sep+item) as f:
                        count = 0
                        for line in f:
                            if line[0:7] == '/*major': 
                                count = 3
                            if count > 0:
                                print line.split()[-1],
                                count -= 1
                                if count == 0: print "  ",item

def print_help():
    print "checkver.py [dir [dir]]"

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print_help()
    else:
        for d in sys.argv[1:]:
            check_dir(d)
